using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class PoolTutorial : MonoBehaviour
{
	private Animator m_Animator;

	[SerializeField]
	private SkeletonAnimation m_SpineAnimation;

	private Image m_Pointer;

	[SerializeField]
	private RectTransform m_SliderSimulation;

	[SerializeField]
	private Text[] m_Texts;

	[SerializeField]
	private GameObject m_ClickArea;

	private Vector3 m_PointerDir;

	private int m_Step;

	private bool m_Aimed;

	private float m_Time;

	private void Awake()
	{
		m_Animator = GetComponentInChildren<Animator>();
		m_Step = 0;
		m_SpineAnimation.UpdateComplete += SpineIdle1PlayComplete;
		m_Texts[0].canvasRenderer.SetAlpha(0.01f);
		m_Texts[1].canvasRenderer.SetAlpha(0.01f);
		m_ClickArea.SetActive(value: false);
		m_Aimed = false;
		base.name = "Tutorial";
	}

	private void Start()
	{
		m_SliderSimulation.transform.position = BaseUIController.fireSlider.transform.position;
		m_Texts[0].CrossFadeAlpha(1f, 0.2f, ignoreTimeScale: false);
		m_Texts[0].text = HOLocalizationConfiguration.GetValue(140);
		Next();
	}

	private void LateUpdate()
	{
		if (m_Step == 2 && MathTools.AngleBetween(BaseUIController.cueAndLines.GetPointerDirection(), m_PointerDir) < 0.1f)
		{
			m_Aimed = true;
			Next();
		}
	}

	private void SpineIdle1PlayComplete(SkeletonRenderer skeletonRenderer)
	{
		m_SpineAnimation.UpdateComplete -= SpineIdle1PlayComplete;
		m_SpineAnimation.AnimationName = "Idle2";
		m_SpineAnimation.loop = true;
	}

	public void OnPointClick(BaseEventData data)
	{
		if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Click"))
		{
			BaseUIController.cueOperateArea.OnAreaPointerClick(data);
			Next();
		}
	}

	public void OnPointerDragBegin(BaseEventData data)
	{
		if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("DragCue"))
		{
			BaseUIController.cueOperateArea.OnAreaDragBegin(data);
		}
	}

	public void OnPointerDrag(BaseEventData data)
	{
		if (!m_Aimed && m_Animator.GetCurrentAnimatorStateInfo(0).IsName("DragCue"))
		{
			BaseUIController.cueOperateArea.OnAreaDrag(data);
		}
	}

	public void OnPointerDragEnd(BaseEventData data)
	{
		BaseUIController.cueOperateArea.OnAreaDragEnd(data);
	}

	public void OnSliderDrag(BaseEventData data)
	{
		if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("DragPower"))
		{
			BaseUIController.fireSlider.OnFireSliderDrag(data);
		}
	}

	public void OnSliderDragEnd(BaseEventData data)
	{
		if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("DragPower") && BaseUIController.fireSlider.lastValue > 0.02f)
		{
			BaseUIController.fireSlider.OnFireSliderDragEnd(data);
			Pools.Cue.SetPowerScalar(0.5f);
			Next();
		}
	}

	public void Next()
	{
		m_Step++;
		m_Animator.SetInteger("TutorialStep1", m_Step);
		int num = m_Step % 2;
		m_Texts[num].text = HOLocalizationConfiguration.GetValue(140 + m_Step - 1);
		m_Texts[num].CrossFadeAlpha(1f, 0.2f, ignoreTimeScale: false);
		m_Texts[1 - num].CrossFadeAlpha(0f, 0.2f, ignoreTimeScale: false);
		if (m_Step == 1)
		{
			m_Animator.transform.position = MathTools.World2UI(Pools.CustomBallsArray[0].transform.position);
			m_ClickArea.SetActive(value: true);
		}
		else if (m_Step == 2)
		{
			m_Animator.transform.position = Vector3.zero;
			m_PointerDir = SupportTools.GetPointerDirWithTargetBallAndTargetPocketUI(Pools.CustomBallsArray[0], PocketTrigger.GetPocketWithIndexes(PocketIndexes.TopRight)).normalized;
		}
		else if (m_Step == 3)
		{
			Vector3 localPosition = BaseUIController.fireSlider.transform.localPosition;
			float y = localPosition.y;
			Vector2 sizeDelta = (BaseUIController.fireSlider.transform as RectTransform).sizeDelta;
			localPosition.y = y + (sizeDelta.y * 0.5f - 30f);
			localPosition.x += 30f;
			m_Animator.transform.position = BaseUIController.fireSlider.transform.parent.TransformPoint(localPosition);
		}
		else if (m_Step > 3)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}

	public void OnNext()
	{
		m_Step++;
		if (m_Step == 4)
		{
			BaseUIController.siding.GetComponent<Animator>().SetTrigger("Show");
		}
		m_Animator.SetInteger("TutorialStep1", m_Step);
		if (m_Step > 4)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}
}
